package design.action.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zxs
 * @since 2020/05/29
 */
public class ConcreteSubject implements Subject{

    private final List<Observer> observers = new ArrayList<>();

    @Override
    public void attach(Observer o) {
        observers.add(o);
    }

    @Override
    public void detach(Observer o) {
        observers.remove(o);
    }

    @Override
    public void notifyAllObserver() {
        observers.forEach(Observer::update);
    }
}
